package com.rg1906.dao.Impl;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.rg1906.utils.DataSourceC3P0ThreadLocal;

public class InsertTeacherDaoImpl {
	DataSource dataSource = DataSourceC3P0ThreadLocal.getDataSource();
	QueryRunner qr = new QueryRunner(dataSource);
	public String getMaxNum(String gid) throws SQLException {
		String sql="select max(teacherNum) from t_teacher where gid=?";
		String studentNum = qr.query(sql, new ScalarHandler<>(),gid);
		return studentNum;
	}
	public int insertTeacher(String teacherName, String gid, String phone, String address, String sex, String age,
			String sNum) throws SQLException {
		Object[] par= {teacherName,gid,phone,address,sex,age,sNum};
		String sql="insert into t_teacher (teacherName,gid,phone,address,sex,age,teacherNum) values(?,?,?,?,?,?,?)";
		return qr.update(sql,par);
	}
	public int insertTeacherSNum(String sNum, int i, String img) throws SQLException {
		String sql="insert into t_user (loginName,rid,img) values (?,?,?)";
		int ii = qr.update(sql,sNum,i,img);
		return ii;
	}
	public int queryID(String sNum) throws SQLException {
		String sql="select id from t_user where loginName=?";
		return qr.query(sql, new ScalarHandler<>(),sNum);
		
	}
	public int insertUid(int gid1, String sNum) throws SQLException {
		String sql="update t_teacher set uid=? where teacherNum =?";
		int i = qr.update(sql,gid1,sNum);
		return i;
	}
}
